<?php
session_start();

$error = false;

if((!isset($_SESSION["user"]))||(!isset($_SESSION["type"])))
	$error = true;

if(($_SESSION["type"] != "user")||($_SESSION["user"] == ""))
	$error = true;

if($error)
{
	session_unset();
	session_destroy();

	header("Location: login.php");
	exit;
}

$utente = $_SESSION["user"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style type="text/css" media="print">
TD {font-size:11px; font-family="arial,helvetica"}
P {text-indent:-10; text-align="justify"; margin-left:10;}
A:link {color: #44aaaa; text-decoration: underline;}
A:active {color: #000000; text-decoration: underline;}
A:visited {color: #227788; text-decoration: underline;}
A:hover {color: #000000; text-decoration: none; }
BODY {font-size:12px; font-family="arial,helvetica";}
FORM {margin-top:5}
</style>
<style type="text/css" media="screen">
TD {font-size:13px}
P {text-indent:-10; text-align="justify"; margin-left:10;}
A:link {color: #44aaaa; text-decoration: underline;}
A:active {color: #000000; text-decoration: underline;}
A:visited {color: #227788; text-decoration: underline;}
A:hover {color: #000000; text-decoration: none;}
BODY {background-image: url(images/captext.gif); font-size:14px}
FORM {margin-top:5}
</style>
</head>

<body>
<center>
<font color="#228888" size="4">
	<br><br><b>BACHECA: AREA LIMITATA PER UTENTI<br><br>Benvenuto <?php echo "<em>$utente</em>"; ?></b><br><br>
</font>
</center>
<center>
<?php
/*******************************/
//Togliere il commento per riabilitare la visione dei messaggi pendenti da parte dell'user
/********************************
require("include/config.inc.php");
require("include/mysql.inc.php");

$db = new MySQL();

$db->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_DEBUG);

$db->query("SELECT * FROM Annuncio_pendente WHERE utente = '$utente' ORDER BY data_pub DESC, codice DESC");

if($db->get_num_rows() > 0)
{
	echo "<span style=\"text-align: center; font-weight: bold; color: black;\">Annunci pendenti.<br><br></span>";
	
	while($row = $db->fetch_array())
	{
		$d_pub = date("d/m/Y", strtotime($row["data_pub"]));
		$d_sca = date("d/m/Y", strtotime($row["data_sca"]));
		
		if(date("Y/m/d", strtotime($row["data_pub"])) < date("Y/m/d"))
			$p_color = "#FF0000";
		else
			$p_color = "#228888";
		
		if(date("Y/m/d", strtotime($row["data_sca"])) <= date("Y/m/d"))
			$scad = "<b>Scadenza: <font color=\"#FF0000\">$d_sca</font></b>";
		else
			$scad = "<b>Scadenza: </b>$d_sca";
		
		$tags = "from=user_opt&to=pendenti&id=" . $row["codice"] . "&data=" . $row["data_pub"] . "&user=" . $row["utente"];
		
		echo "<table style=\"table-layout: fixed; width:90%; margin-left: auto; margin-right: auto;\">
			  <tr bgcolor=\"#FFDFBF\">
			  	<td style=\"text-align: center;\" width=\"45px\">
					<a href=\"write_msg.php?action=mod&$tags\" title=\"Modifica\"><img src=\"images/msg_mod.png\" alt=\"Modifica\" style=\"border: 0px;\" width=\"14px\" height=\"14px\"></a>
					<a href=\"gestione_msg.php?action=del&$tags\" title=\"Elimina\" onclick=\"javascript: return(confirm('Eliminare permanentemente il messaggio?'))\"><img src=\"images/msg_del.png\" alt=\"Elimina\" style=\"border: 0px;\" width=\"14px\" height=\"14px\"></a>
				</td>
				<td><b>Pubblicato in data: <font color=\"$p_color\" size=\"3\">$d_pub</font></b></td>
				<td align=\"right\"><b>Autore: </b>" . $row["autore"] . "</td>
				<td align=\"right\">$scad</td>
			  </tr>
			  <tr><td colspan=\"4\">" . str_replace("\n", "<br>", $row["corpo"]) . "</td></tr>
			  </table>";
	}
}
else
	echo "<span style=\"text-align: center; font-weight: bold; color: black;\">Non ci sono annunci pendenti.</span>";

$db->free_result();
$db->close();
/*******************************/
?>
<br>
<?php
if(@$_GET["pmsg"] == "send")
	echo "<span style=\"text-align: center; font-weight: bold; color: black;\">Il messaggio &egrave; stato inviato con successo.<br><br></span>";

if(@$_GET["pmsg" == "error"])
	echo "<span style=\"text-align: center; font-weight: bold; color: red;\">Errore nell'invio del messaggio.<br><br></span>";
?>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tr>
	<td style="vertical-align: middle; text-align: center;" width="30%"><a href="pubblicati.php">Avvisi Pubblicati</a></td>
	<td style="vertical-align: middle; text-align: center;" width="30%">
		<a href="write_msg.php?from=user_opt&to=pendenti">Nuovo Messaggio</a><br><br>
		<a href="ricerca_msg.php?from=user_opt">Cerca nei Messaggi</a><br><br>
		<a href="javascript: location.reload(true);">REFRESH</a>
	</td>
	<td style="vertical-align: middle; text-align: center;" width="30%"><a href="check.php?action=logout">Logout</a></td>
</tr>
</table>
</center>
<br>
<table bgcolor="#88CCCC" border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
	<td> Ultima modifica: <?php echo date("d/m/Y");?></td>
	<td align="right"> Approvato da: Presidente CCdL</td>
</tr>
</table>
</body>
</html>
